<template>

  <el-form ref="ruleFormRef" style="max-width: 600px" :model="Ridgepoles" :rules="rules" label-width="auto"
    class="demo-ruleForm" :size="formSize" status-icon>



    <el-form-item label="品种" prop="ridgepoleTypeId">
      <el-select v-model="Ridgepoles.ridgepoleTypeId" placeholder="请选择" size="large" style="width: 240px">
        <el-option v-for="item in GetBreed" :key="item.value" :label="item.name" :value="item.value" />
      </el-select>
    </el-form-item>


    <el-form-item label="栋舍名称" prop="ridgepoleName">
      <el-input v-model="Ridgepoles.ridgepoleName" />
    </el-form-item>

    <el-form-item label="负责人" prop="responsiblePerson">
      <el-input v-model="Ridgepoles.responsiblePerson" />
    </el-form-item>

    <el-form-item label="生产人员" prop="productionPersonnel">
      <el-input v-model="Ridgepoles.productionPersonnel" />
    </el-form-item>


  <!-- 
      <el-form-item label="状态" prop="state">
        <el-radio-group v-model="Ridgepoles.state">
          <el-radio value="1" >启用</el-radio>
          <el-radio value="0">禁用</el-radio>
        </el-radio-group>
      </el-form-item> -->


    <el-form-item label="备注" prop="remark">
      <el-input v-model="Ridgepoles.remark" />
    </el-form-item>







    <el-form-item>
      <el-button type="primary" @click="submitForm(ruleFormRef)">
        添加
      </el-button>

    </el-form-item>
  </el-form>
</template>

<script lang="ts" setup>
import { reactive, ref } from 'vue'
import type { ComponentSize, FormInstance, FormRules } from 'element-plus'
import { RidgepoleAdd } from "@/api/OrganizationalAdministration/index";


import starts from "@/api/EarTagManagement/index";
import start from "@/api/EarTagManagement/index";
import { EartagAdd } from "@/api/EarTagManagement/model";
import axios from "axios";
import { number } from "echarts";
import { useRouter, useRoute } from 'vue-router';
const useRoutes = useRouter()
const useRoutea = useRoute()
import vendor from "@/api/OrganizationalAdministration/index";

const GetBreed = ref([])
const GetShowEarBreed = () => {
  vendor.GetShowbreed().then((res: any) => {
    GetBreed.value = res.data
  })
}
const GetBreedPeoPle = ref([])
const GetShowPeople = () => {
  vendor.GetShowPeople().then((res: any) => {
    GetBreedPeoPle.value = res.data
  })
}

onMounted(() => {
  GetShowEarBreed()
  GetShowPeople()
})

const Ridgepoles = reactive<RidgepoleAdd>({
  ridgepoleTypeId: null,
  ridgepoleName: "",
  responsiblePerson: "",
  productionPersonnel: "",
  state: 1,
  remark: "",
  createName: "",
  createTime: "2024-07-31",
  updateName: "string",
  updateTime: "2024-07-31",
  sheepId: 0,
});

const formSize = ref('default')
const ruleFormRef = ref()



const rules = reactive({
  ridgepoleTypeId: [
    { required: true, message: '品种不能为空', trigger: 'blur' }
  ],
  ridgepoleName: [
    { required: true, message: '栋舍名称不能为空', trigger: 'blur' }
  ],
  responsiblePerson: [
    { required: true, message: '负责人不能为空', trigger: 'blur' }
  ],
  productionPersonnel: [
    { required: true, message: '生产人员不能为空', trigger: 'blur' }
  ],
  state: [
    { required: true, message: '状态不能为空', trigger: 'blur' }
  ],
  remark: [
    { required: true, message: '备注不能为空', trigger: 'blur' }
  ],
})

const submitForm = async (formEl: FormInstance | undefined) => {
  if (!formEl) return
  await formEl.validate((valid, fields) => {
    if (valid) {
      vendor.AddRan(Ridgepoles).then(res => {
        if (res.data > 0) {
          ElMessage.success("添加成功");
          useRoutes.push("/ridgepolefieds")
        }
      })
    } else {
      console.log('error submit!', fields)
    }
  })
}




</script>
